<template>
  <div class="item">
    <van-nav-bar title="会员注册" left-arrow @click-left="onClickLeft" />
    <div>
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          placeholder="手机号码"
          :rules="[{ required: true }]"
        />
        <!--小眼睛 -->
        <van-icon name="eye-o" size="25px" @click="changeType" :color="color" />

        <!-- 通过 validator 进行函数校验 -->
        <van-field
          v-model="password"
          :type="type"
          name="password"
          placeholder="请输入登录密码"
          :rules="[{ required: true }]"
        />

        <!-- 小眼睛 -->
        <van-icon
          name="eye-o"
          size="25px"
          class="eye"
          @click="changeType2"
          :color="color2"
        />

        <van-field
          v-model="password1"
          :type="type2"
          name="password1"
          placeholder="请输入确认密码"
          :rules="[{ required: true, message: message }]"
        />

        <van-row type="flex">
          <van-field
            v-model="captcha"
            name="captcha"
            placeholder="请输入图形验证"
            :rules="[{ required: true }]"
          />
          <!-- 再次确认面 -->

          <!-- 验证码 -->
          <captcha ref="captcha" />
        </van-row>
        <div class="login-type-area">
          <div class="but">
            <div v-if="check" @click="changeCheck"></div>
            <div v-if="!check" @click="changeCheck" class="active">
              <van-icon name="success" color="white" style="margin-left: 2px" />
            </div>
            <div>
              已阅读并同意<span style="color: #079efb"
                >《中兴商城隐私政策》</span
              >
            </div>
          </div>
        </div>
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            color="red"
            style="width: 325px; margin: auto"
            >注册</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Form } from "vant";
import { Field, Button, Toast, Icon, NavBar } from "vant";
import Captcha from "@/components/Captcha.vue";
import { Col, Row } from "vant";
Vue.use(NavBar);
Vue.use(Col);
Vue.use(Row);
Vue.use(Toast);
Vue.use(Button);
Vue.use(Form);
Vue.use(Field);
Vue.use(Icon);

export default {
  components: { Captcha },
  data() {
    return {
      username: "",
      password: "",
      password1: "",
      captcha: "",
      Type: true,
      Type2: true,
      check: true,
      capShow: false,
      type: "password",
      type2: "password",
      color: "",
      color2: "",
      message: "请填写密码",
    };
  },
  methods: {
    onSubmit(values) {
      if (values.password != values.password1) {
        console.log(1);
        Toast("两次密码不一致");
        this.message = "两次密码不一致";
      }
      if (this.check == true) {
        Toast("请阅读并同意中兴手机商城隐私政策");
      } else {
        console.log("submit", values);
      }
    },

    changeType() {
      console.log(1);
      this.Type = !this.Type;
      this.type = this.Type ? "password" : "text";
      this.color = this.Type ? "" : "skyblue";
    },
    changeCheck() {
      this.check = !this.check;
    },
    changeType2() {
      this.Type2 = !this.Type2;
      this.type2 = this.Type2 ? "password" : "text";
      this.color2 = this.Type2 ? "" : "skyblue";
    },
    onClickLeft() {
      this.$router.push("/login");
    },
  },
  mounted() {
    if (!this.check) {
    }
  },
  created() {
    this.$store.commit("changeFooter");
  },
  beforeDestroy() {
    this.$store.commit("changeFooter");
  },
};
</script>

<style lang="scss" scoped>
.item {
  overflow: hidden;
  width: 100%;

  .van-cell {
    border-radius: 44px;
    width: 325px;
    box-sizing: border-box;
    margin: 20px auto;
    background: #f4f4f4;
    position: relative;
  }
  .van-icon-eye-o {
    position: absolute;
    top: 140px;
    right: 112px;
    z-index: 111;
  }
  .eye {
    position: absolute;
    z-index: 111;
    top: 205px;
  }
  .captcha {
    position: absolute;
    top: 30px;

    right: 50px;
    box-sizing: box;
  }
  .van-row {
    position: relative;
  }
  .login-btn-other-pg {
    width: 325px;
    height: 54px;
    margin: 0 25px 11.5px;
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    color: #1e1e1e;
    cursor: pointer;
  }
  .login-type-area {
    margin-bottom: 0.85333rem;

    .but {
      display: flex;
      justify-content: center;
      align-items: center;
      > div:nth-child(1) {
        width: 20px;
        height: 20px;
        margin-right: 5px;
        border: solid 0.064rem rgba(0, 0, 0, 0.44);
        border-radius: 100%;
      }
      width: 250px;
      height: 20px;
      margin: auto;
    }
  }
}
.active {
  border: solid 0.064rem #079efb;
  background: #079efb;
}
.van-button {
  position: fixed;
  bottom: 20px;
  text-align: center;
}
</style>
